package com.yishan.controller;


import com.yishan.domain.User;
import com.yishan.response.Response;
import com.yishan.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @author:别纪元
 * @create:2024/1/6 9:33
 */
@Controller
@RequestMapping("token")
public class TokenController {

    @Autowired
    private JwtUtils jwtUtils;

    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 获取token
     * @return
     */
    @PostMapping("get/token")
    @ResponseBody
    public Response getToken(User user){
        if (!"admin".equals(user.getUserName())){
            return Response.error("用户名错误");
        }
        if (!"admin".equals(user.getPassWord())){
            return Response.error("密码错误");
        }
        String jwt = jwtUtils.createJWT(user.getUserName(), user.getPassWord());
        System.out.println(jwt);
        return Response.success(jwt);
    }

    /**
     * token校验
     * @return
     */
    @GetMapping("getMovie")
    public String checkToken(){
        return "/ceshi";
    }
}
